//返回功能
function fanHui0() {
    history.back();
}


var y = /^1[345789]\d{9}$/;
//手机号码栏js开始
num1.onkeyup = function () {
    if(num1.value!=""){
        chaCha.src = "images/删除.png";
    }else{
        chaCha.src = "";
    }
};
chaCha.onclick = function () {
    num1.value = "";
};
//密码栏js
function guanBi(){
    promptbox.style.display = "none";
    promptbox.innerHTML = "";
}



var pwdReg0 = /^.{6,16}$/;
var pwdReg1 = /\d+/;
var pwdReg2 = /[a-zA-Z]+/;
var pwdReg3 = /[=~!@#\$%^&\*\(\)_\+\{\}\]:"\|',<?.\/\\]+/;




yanjin.onclick = function () {

    if(pwd1.type == "password"){
        yanjin.src = "images/眼睛 (1).png";
        pwd1.type = "text";
    }else{
        yanjin.src = "images/眼睛2.png";
        pwd1.type = "password";
    }

};




loginbtn.onclick = function(){
    loginbtn.value = "登录中";
    if(!y.test(num1.value)){
        loginbtn.value = "登录";
        promptbox.style.display = "block";
        promptbox.innerHTML = "手机号格式有误！";
        setTimeout(guanBi,2000);
    }else{
        var x = pwd1.value;
        var rightCount = 0;
        var lengthValid = pwdReg0.test(x);
        var numberValid = pwdReg1.test(x);
        var letterValid = pwdReg2.test(x);
        var symbolValid = pwdReg3.test(x);
        if(numberValid){
            rightCount++;
        }
        if(letterValid){
            rightCount++;
        }
        if(symbolValid){
            rightCount++;
        }
        if(!lengthValid||rightCount<2){
            loginbtn.value = "登录";
            promptbox.style.display = "block";
            promptbox.innerHTML = "密码格式有误！";
            setTimeout(guanBi,2000);
        }else{
            $.post("http://test.hfjava.com/shop/userlogin",
                $("form").serialize(),
                function(data){
                    loginbtn.value = "登录";
                    console.log(data);
                    if(data=="false"){
                        promptbox.style.display = "block";
                        promptbox.innerHTML = "用户名或密码有误！";
                        setTimeout(guanBi,2000);
                    }else{
                        promptbox.style.display = "block";
                        promptbox.innerHTML = "登录成功！";
                        localStorage.setItem("bc",num1.value);
                        setTimeout(guanBi,2000);
                    }
                }
            );
        }

    }
};

//保存登录成功的值到本地
if(localStorage.getItem("bc")){
    num1.value = localStorage.getItem("bc");
}